<template>
  <div class="app-container">
    <el-card class="box-card">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true"  label-width="88px">
      <el-form-item label="告知单编号" prop="adviseNo">
        <el-input
          v-model="queryParams.adviseNo"
          placeholder="请输入告知单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="流水号" prop="sequenceNumber">
        <el-input
          v-model="queryParams.sequenceNumber"
          placeholder="请输入流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
     <!-- <el-form-item label="监管JDS" prop="representativeOffice">
        <el-select
          v-model="queryParams.representativeOffice"
          placeholder="请选择监管JDS"
          clearable
        >
          <el-option
            v-for="dict in dict.type.yh_representative_office"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>-->
      <el-form-item label="风险来源" prop="riskOrigin">
        <el-input
          v-model="queryParams.riskOrigin"
          placeholder="请输入风险来源"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="发生原因" prop="occurrenceReason" >
        <el-input
          v-model="queryParams.occurrenceReason"
          placeholder="请输入发生原因"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="潜在后果" prop="consequence" v-show="showSearch">
        <el-input
          v-model="queryParams.consequence"
          placeholder="请输入潜在后果"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="影响范围" prop="influenceScope" v-show="showSearch">
        <el-input
          v-model="queryParams.influenceScope"
          placeholder="请输入影响范围"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="概率等级" prop="probabilityLevel" v-show="showSearch">
        <el-select
          v-model="queryParams.probabilityLevel"
          placeholder="请选择概率等级"
          clearable
        >
          <el-option
            v-for="dict in dict.type.yh_probability_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="后果等级" prop="consequencesLevel" v-show="showSearch">
        <el-select
          v-model="queryParams.consequencesLevel"
          placeholder="请选择后果等级"
          clearable
        >
          <el-option
            v-for="dict in dict.type.yh_consequences_level"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!--
     <el-form-item label="是否关闭" prop="suspend">
       <el-input
         v-model="queryParams.suspend"
         placeholder="请输入是否关闭"
         clearable
         @keyup.enter.native="handleQuery"
       />
     </el-form-item>
     <el-form-item label="关闭日期" prop="suspendDate">
       <el-input
         v-model="queryParams.suspendDate"
         placeholder="请输入关闭日期"
         clearable
         @keyup.enter.native="handleQuery"
       />
     </el-form-item>
     <el-form-item label="关闭说明" prop="suspendDeclare">
       <el-input
         v-model="queryParams.suspendDeclare"
         placeholder="请输入关闭说明"
         clearable
         @keyup.enter.native="handleQuery"
       />
     </el-form-item>
     -->
      <br/>
      <div style="text-align: right;">
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </div>
    </el-form>
      <br/>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['module:cjl:project:add']"
        >新增</el-button>
      </el-col>
     <!-- <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['module:cjl:project:edit']"
        >修改</el-button>
      </el-col>-->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['module:cjl:project:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['module:cjl:project:import']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['module:cjl:project:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="projectList" border @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" width="55" :index="indexMethod" align="center" />
      <!--<el-table-column label="序号" align="center" prop="id" width="60"/>-->
      <el-table-column label="告知单编号" align="center" prop="adviseNo" v-if="columns[0].visible"/>
      <el-table-column label="流水号" align="center" prop="sequenceNumber" v-if="columns[1].visible"/>
      <el-table-column label="监管JDS" align="center" prop="representativeOffice" v-if="columns[2].visible" >
      <template slot-scope="scope">
        <dict-tag :options="dict.type.yh_representative_office" :value="scope.row.representativeOffice"/>
      </template>
      </el-table-column>
      <el-table-column label="风险来源" align="center" prop="riskOrigin" v-if="columns[3].visible"/>
      <el-table-column label="发生原因" align="center" prop="occurrenceReason" v-if="columns[4].visible"/>
      <el-table-column label="潜在后果" align="center" prop="consequence" v-if="columns[5].visible"/>
      <el-table-column label="影响范围" align="center" prop="influenceScope" v-if="columns[6].visible"/>
      <el-table-column label="概率等级" align="center" prop="probabilityLevel" v-if="columns[7].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yh_probability_level" :value="scope.row.probabilityLevel"/>
        </template>
      </el-table-column>
      <el-table-column label="后果等级" align="center" prop="consequencesLevel" v-if="columns[8].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yh_consequences_level" :value="scope.row.consequencesLevel"/>
        </template>
      </el-table-column>
      <el-table-column label="是否关闭" align="center" prop="suspend" v-if="columns[9].visible">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.yh_suspend" :value="scope.row.suspend"/>
        </template>
      </el-table-column>
      <el-table-column label="关闭日期" align="center" prop="suspendDate" v-if="columns[10].visible"/>
      <el-table-column label="关闭说明" align="center" prop="suspendDeclare" v-if="columns[11].visible"/>
      <el-table-column label="备注" align="center" prop="remark" v-if="columns[12].visible"/>
      <el-table-column label="操作" align="center" width="160" class-name="small-padding fixed-width" fixed="right">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['module:cjl:project:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
            v-hasPermi="['module:cjl:project:remove']"
          >删除</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleView(scope.row,scope.index)"
            v-hasPermi="['module:cjl:project:view']"
          >详细</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    </el-card>
    <!-- 添加或修改项目风险对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="1200px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="100px">
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">监管任务信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <!--<el-col :span="8">
                <el-form-item label="告知单编号" prop="adviseNo">
                  <el-input v-model="form.adviseNo" placeholder="请输入告知单编号" style="width: 100%"  clearable/>
                </el-form-item>
              </el-col>-->
              <el-col :span="8">
                <el-form-item label="流水号" prop="sequenceNumber">
                  <el-autocomplete
                    clearable
                    v-model="form.sequenceNumber"
                    placeholder="请输入流水号"
                    style="width: 100%"
                    :fetch-suggestions="querySearchAsync"
                    @select="handleSelect"
                  >
                  </el-autocomplete>
                 <!-- <el-input v-model="form.sequenceNumber" placeholder="请输入流水号" style="width: 100%"/>-->
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="监管JDS" prop="representativeOffice">
                 <!-- <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true" placeholder="请选择监管JDS" />-->
                  <el-select v-model="form.representativeOffice" placeholder="请选择监管JDS" style="width: 100%" clearable>
                    <el-option
                      v-for="dict in dict.type.yh_representative_office"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
           <!-- <el-row>
              <el-col :span="8">
                <el-form-item label="风险来源" prop="riskOrigin">
                  <el-input v-model="form.riskOrigin" placeholder="请输入风险来源" style="width: 100%"  clearable/>
                </el-form-item>
              </el-col>
            </el-row>-->
          </el-main>
        </el-container>
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">风险信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col :span="8">
                <el-form-item label="告知单编号" prop="adviseNo">
                  <el-input v-model="form.adviseNo" placeholder="请输入告知单编号" style="width: 100%"  clearable/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="发生原因" prop="occurrenceReason">
                  <el-input v-model="form.occurrenceReason" placeholder="请输入发生原因" style="width: 100%"  clearable/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="潜在后果" prop="consequence">
                  <el-input v-model="form.consequence" placeholder="请输入潜在后果" style="width: 100%"  clearable/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="风险来源" prop="riskOrigin">
                  <el-input v-model="form.riskOrigin" placeholder="请输入风险来源" style="width: 100%"  clearable/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="影响范围" prop="influenceScope">
                  <el-input v-model="form.influenceScope" placeholder="请输入影响范围" style="width: 100%"  clearable/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="概率等级" prop="probabilityLevel">
                  <el-select v-model="form.probabilityLevel" placeholder="请选择概率等级" style="width: 100%"  clearable>
                    <el-option
                      v-for="dict in dict.type.yh_probability_level"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                  <!--<el-input v-model="form.probabilityLevel" placeholder="请输入概率等级" />-->
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
            <!--  <el-col :span="8">
                <el-form-item label="概率等级" prop="probabilityLevel">
                  <el-select v-model="form.probabilityLevel" placeholder="请选择概率等级" style="width: 100%"  clearable>
                    <el-option
                      v-for="dict in dict.type.yh_probability_level"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>-->
              <el-col :span="8">
                <el-form-item label="后果等级" prop="consequencesLevel">
                  <el-select v-model="form.consequencesLevel" placeholder="请选择后果等级" style="width: 100%"  clearable>
                    <el-option
                      v-for="dict in dict.type.yh_consequences_level"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                  <!--<el-input v-model="form.consequencesLevel" placeholder="请输入后果等级" />-->
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否关闭" prop="suspend">
                  <el-radio-group v-model="form.suspend">
                    <el-radio
                      style="float:left"
                      v-for="dict in dict.type.yh_suspend"
                      :key="dict.value"
                      :label="dict.value"
                    >{{dict.label}}</el-radio>
                  </el-radio-group>
                  <!--<el-select v-model="form.suspend" placeholder="请选择是否关闭" style="width: 100%"  clearable>
                    <el-option
                      v-for="dict in dict.type.yh_suspend"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>-->
                  <!--<el-input v-model="form.suspend" placeholder="请输入是否关闭" />-->
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="关闭日期" prop="suspendDate" v-if="form.suspend == '1'" >
                  <el-date-picker
                    clearable
                    style="width: 100%"
                    v-model="form.suspendDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    placeholder="请输入关闭日期">
                  </el-date-picker>
                  <!--<el-input v-model="form.suspendDate" placeholder="请输入关闭日期" style="width: 95%"/>-->
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="关闭说明" prop="suspendDeclare">
              <!--<editor v-model="form.suspendDeclare"  placeholder="请输入关闭说明" :min-height="168" />-->
              <el-input v-model="form.suspendDeclare" type="textarea" placeholder="请输入关闭说明" maxlength="100"/>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" maxlength="500"/>
            </el-form-item>
          </el-main>
        </el-container>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的项目风险数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="danger" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 查看项目风险信息对话框 -->
    <el-dialog :title="view.title" :visible.sync="view.open" width="1200px" append-to-body :close-on-click-modal="false">
      <el-form ref="form" :model="form" :rules="rules" label-width="130px">
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">项目风险基本信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col :span="8">
                <el-form-item label="告知单编号" prop="adviseNo">
                  <el-input v-model="form.adviseNo"  style="width: 100%" readonly="true"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="流水号" prop="sequenceNumber">
                  <el-input v-model="form.sequenceNumber"  style="width: 100%" readonly="true"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="监管JDS" prop="deptId">
                  <treeselect v-model="form.deptId" :options="deptOptions" :show-count="true"  disabled="true"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="风险来源" prop="riskOrigin">
                  <el-input v-model="form.riskOrigin"  style="width: 100%" readonly="true"/>
                </el-form-item>
              </el-col>
            </el-row>
          </el-main>
        </el-container>
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">项目风险原因信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col :span="8">
                <el-form-item label="发生原因" prop="occurrenceReason">
                  <el-input v-model="form.occurrenceReason"  style="width: 100%" readonly="true"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="潜在后果" prop="consequence">
                  <el-input v-model="form.consequence"  style="width: 100%" readonly="true"/>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="影响范围" prop="influenceScope">
                  <el-input v-model="form.influenceScope"  style="width: 100%" readonly="true"/>
                </el-form-item>
              </el-col>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="概率等级" prop="probabilityLevel">
                  <el-select v-model="form.probabilityLevel"  style="width: 100%" disabled="true">
                    <el-option
                      v-for="dict in dict.type.yh_probability_level"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
            </el-row>
          </el-main>
        </el-container>
        <el-container>
          <el-header>
            <el-divider content-position="left">
              <p style="color: #00afff; font-size: 20px;">项目风险后果信息</p>
            </el-divider>
          </el-header>
          <el-main>
            <el-row>
              <el-col :span="8">
                <el-form-item label="后果等级" prop="consequencesLevel">
                  <el-select v-model="form.consequencesLevel"  style="width: 100%" disabled="true">
                    <el-option
                      v-for="dict in dict.type.yh_consequences_level"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="是否关闭" prop="suspend">
                  <el-select v-model="form.suspend"  style="width: 100%" disabled="true">
                    <el-option
                      v-for="dict in dict.type.yh_suspend"
                      :key="dict.value"
                      :label="dict.label"
                      :value="dict.value"
                    ></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="关闭日期" prop="suspendDate">
                  <el-date-picker
                    clearable
                    style="width: 100%"
                    v-model="form.suspendDate"
                    type="date"
                    value-format="yyyy-MM-dd"
                    readonly="true"
                  >
                  </el-date-picker>
                </el-form-item>
              </el-col>
            </el-row>
            <el-form-item label="关闭说明" prop="suspendDeclare">
              <el-input v-model="form.suspendDeclare" type="textarea"  readonly="true"/>
            </el-form-item>
            <el-form-item label="备注" prop="remark">
              <el-input v-model="form.remark" type="textarea"  readonly="true"/>
            </el-form-item>
          </el-main>
        </el-container>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="viewCancel">返 回</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import { listProject, getProject, delProject, addProject, updateProject } from "@/api/module/cjl/project";
  import { getToken } from "@/utils/auth";
  import { treeselect } from "@/api/system/dept";
  import Treeselect from "@riophae/vue-treeselect";
  import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  import watermark from "watermark-dom";
  import { listSearchContract} from "@/api/module/cjl/contract";
  export default {
    name: "Project",
    dicts: ['yh_probability_level', 'yh_representative_office','yh_consequences_level','yh_suspend'],
    components: { Treeselect },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: false,
        // 总条数
        total: 0,
        // 部门树选项
        deptOptions: undefined,
        // 项目风险表格数据
        projectList: [],
        // 合同台账表格数据
        contractList: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          adviseNo: null,
          sequenceNumber: null,
          representativeOffice: null,
          riskOrigin: null,
          occurrenceReason: null,
          consequence: null,
          influenceScope: null,
          probabilityLevel: null,
          consequencesLevel: null,
          suspend: null,
          suspendDate: null,
          suspendDeclare: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          note1: null,
          note2: null,
          note3: null,
          note4: null,
          note5: null,
          note6: null,
          note7: null,
          note8: null,
          note9: null,
          note10: null,
          orderByColumn:"createTime",
          isAsc:"desc"
        },
        // 表单参数
        form: {},
        // 用户查询参数
        view:{
          // 是否显示弹出层（用户查询）
          open: false,
          // 弹出层标题（用户查询）
          title: "",
        },
        // 用户导入参数
        upload: {
          // 是否显示弹出层（用户导入）
          open: false,
          // 弹出层标题（用户导入）
          title: "",
          // 是否禁用上传
          isUploading: false,
          // 是否更新已经存在的用户数据
          updateSupport: 0,
          // 设置上传的请求头部project
          headers: { Authorization: "Bearer " + getToken() },
          // 上传的地址
          url: process.env.VUE_APP_BASE_API + "/module/cjl/project/importData"
        },
        // 列信息
        columns: [
          { key: 0, label: `告知单编号`, visible: true },
          { key: 1, label: `流水号`, visible: true },
          { key: 2, label: `监管JDS`, visible: false },
          { key: 3, label: `风险来源`, visible: true },
          { key: 4, label: `发生原因`, visible: true },
          { key: 5, label: `潜在后果`, visible: true },
          { key: 6, label: `影响范围`, visible: true },
          { key: 7, label: `概率等级`, visible: false },
          { key: 8, label: `后果等级`, visible: false},
          { key: 9, label: `是否关闭`, visible: false },
          { key: 10, label: `关闭日期`, visible: false  },
          { key: 11, label: `关闭说明`, visible: false },
          { key: 12, label: `备注`, visible: false }
        ],
        // 表单校验
        rules: {
          adviseNo: [
            { required: true, message: "告知单编号不能为空", trigger: "blur" },
          ],
          /*sequenceNumber: [
            { required: true, message: "流水号不能为空", trigger: "blur" },
          ],*/
          representativeOffice: [
            { required: true, message: "监管JDS不能为空", trigger: "blur" },
          ],
          occurrenceReason: [
            { required: true, message: "发生原因不能为空", trigger: "blur" },
          ],
        }
      };
    },
    mounted() {
      watermark.load({ watermark_txt: "  "   });
    },
    created() {
      this.getList();
      this.getTreeselect();
      this.getContractInfo();
    },
    methods: {
      /** 查询合同台账列表 */
      getContractInfo() {
        listSearchContract(this.queryParams).then(response => {
          this.contractList = response.rows;
        });
      },
      querySearchAsync(queryString, cb) {
        let contractInfoJson= JSON.parse(JSON.stringify(this.contractList).replace(/sequenceNumber/g,"value"));
        let results = queryString ? contractInfoJson.filter(this.createStateFilter(queryString)) : contractInfoJson;
        clearTimeout(this.timeout);
        this.timeout = setTimeout(() => {
          cb(results);
        }, 0.5*1000);
      },
      //根据输入的字段进行筛选
      createStateFilter(queryString) {
        return (state) => {
          return (state.value.toString().toLowerCase().indexOf(queryString.toLowerCase()) === 0);
        };
      },
      //将其他数据自动补全，采用覆盖的方法
      handleSelect(item){
        this.form.sequenceNumber = item.value;
        this.form.representativeOffice=item.representativeOffice;
      },
      indexMethod(index) {
        index = (index + 1) + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
        return index
      },
      /** 查询项目风险列表 */
      getList() {
        this.loading = true;
        listProject(this.queryParams).then(response => {
          this.projectList = response.rows;
          this.total = response.total;
          this.loading = false;
        });
      },
      /** 查询部门下拉树结构 */
      getTreeselect() {
        treeselect().then(response => {
          this.deptOptions = response.data;
        });
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 取消按钮
      viewCancel() {
        this.view.open = false;
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          adviseNo: null,
          sequenceNumber: null,
          representativeOffice: null,
          riskOrigin: null,
          occurrenceReason: null,
          consequence: null,
          influenceScope: null,
          probabilityLevel: null,
          consequencesLevel: null,
          suspend: null,
          suspendDate: null,
          suspendDeclare: null,
          createBy: null,
          createTime: null,
          updateBy: null,
          updateTime: null,
          remark: null,
          note1: null,
          note2: null,
          note3: null,
          note4: null,
          note5: null,
          note6: null,
          note7: null,
          note8: null,
          note9: null,
          note10: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.is=selection.map(item => item.adviseNo)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 新增按钮操作 */
      handleAdd() {
        this.reset();
        this.open = true;
        this.title = "添加项目风险";
      },
      /** 修改按钮操作 */
      handleUpdate(row) {
        this.reset();
        const id = row.id || this.ids
        getProject(id).then(response => {
          this.form = response.data;
          this.open = true;
          this.title = "修改项目风险";
        });
      },
      /** 提交按钮 */
      submitForm() {
        this.$refs["form"].validate(valid => {
          if (valid) {
            if (this.form.id != null) {
              updateProject(this.form).then(response => {
                this.$modal.msgSuccess("修改成功");
                this.open = false;
                this.getList();
              });
            } else {
              addProject(this.form).then(response => {
                this.$modal.msgSuccess("新增成功");
                this.open = false;
                this.getList();
              });
            }
          }
        });
      },
      /** 详细按钮操作 */
      handleView(row) {
        /*const id = row.id || this.ids
        getProject(id).then(response => {
          this.form = response.data;
          this.view.open = true;
          this.view.title = "查看项目风险信息";
        });*/
        const id = row.id;
        this.$router.push({ path:"/hetong/project_detail", query: {id}});
      },
      /** 删除按钮操作 */
      handleDelete(row) {
        const ids = row.id || this.ids;
        const i=row.adviseNo || this.is;
        this.$modal.confirm('是否确认删除告知单编号为"' + i + '"的数据项？').then(function() {
          return delProject(ids);
        }).then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        }).catch(() => {});
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('module/cjl/project/export', {
          ...this.queryParams
        }, `project_${new Date().getTime()}.xlsx`)
      },
      /** 导入按钮操作 */
      handleImport() {
        this.upload.title = "项目风险信息导入";
        this.upload.open = true;
      },
      /** 下载模板操作 */
      importTemplate() {
        this.download('module/cjl/project/importTemplate', {
        }, `project_template_${new Date().getTime()}.xlsx`)
      },
      // 文件上传中处理
      handleFileUploadProgress(event, file, fileList) {
        this.upload.isUploading = true;
      },
      // 文件上传成功处理
      handleFileSuccess(response, file, fileList) {
        this.upload.open = false;
        this.upload.isUploading = false;
        this.$refs.upload.clearFiles();
        this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
        this.getList();
      },
      // 提交上传文件
      submitFileForm() {
        this.$refs.upload.submit();
      }
    }
  };
</script>
<style>
  .el-header, .el-footer {
    background-color: #FFFFFF;
    color: #333;
    text-align: left;
    line-height: 60px;
    font-style: oblique;

  }

  .el-aside {
    background-color: #D3DCE6;
    color: #333;
    text-align: center;
    line-height: 200px;
  }
  body > .el-container {
    margin-bottom: 40px;
  }

  .el-container:nth-child(5) .el-aside,
  .el-container:nth-child(6) .el-aside {
    line-height: 260px;
  }

  .el-container:nth-child(7) .el-aside {
    line-height: 320px;
  }

  /*对话框标题样式*/
  .el-dialog__title{
    /*color: #1ab394;*/
    font-weight: bold;
    font-size: 25px;
  }
</style>
